package com.aidex.system.controller;

import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.system.domain.Agent;
import com.aidex.system.domain.VCsisBusinessAsd;
import com.aidex.system.domain.vo.AgentVO;
import com.aidex.system.domain.vo.WaybillVO;
import com.aidex.system.mapper.AgentMapper;
import com.aidex.system.mapper.WaybillMapper;
import com.aidex.system.service.AgentService;
import com.aidex.system.service.WaybillService;
import com.aidex.system.service.impl.WaybillServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 接口日志Controller
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-11-14
 */
@RestController
@RequestMapping("/system/agent")
public class AgentController extends BaseController {
    @Autowired
    private AgentService agentService;

    @Resource
    private AgentMapper agentMapper;
    @Autowired
    WaybillService waybillService;
    /**
     * 查询接口日志列表
     */
    @GetMapping("/page")
    public R<PageInfo> list(AgentVO query) {
        PageDomain page = new PageDomain();
        page.setPageNum(query.getPageNum());
        page.setPageSize(query.getPageSize());
        query.setPage(page);
        PageHelper.startPage(page.getPageNum(), page.getPageSize(), page.getOrderBy());

        List<Agent> list = agentMapper.page(query);
        List<Agent> newList= new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Agent item = list.get(i);
            if(item.getType() != null && item.getType()==2){
                item.setAgentName(item.getAgentName()+"-"+item.getAgentId());
                newList.add(item);
            }
        }
        return R.data(new PageInfo(newList));
    }

    @GetMapping("/test")
    public String list() {
        waybillService.syncWlptTestClass();
        return "OK";
    }
}
